package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.UserFactorItemOp;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserFactorItem;
import com.ruoyi.system.service.IUserFactorItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自定义因子Controller
 * 
 * @author ruoyi
 * @date 2022-01-26
 */
@RestController
@RequestMapping("/system/item")
public class UserFactorItemController extends BaseController
{
    @Autowired
    private IUserFactorItemService userFactorItemService;

    /**
     * 查询自定义因子列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserFactorItem userFactorItem)
    {
        startPage();
        List<UserFactorItem> list = userFactorItemService.selectUserFactorItemList(userFactorItem);
        return getDataTable(list);
    }

    /**
     * 导出自定义因子列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "自定义因子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserFactorItem userFactorItem)
    {
        List<UserFactorItem> list = userFactorItemService.selectUserFactorItemList(userFactorItem);
        ExcelUtil<UserFactorItem> util = new ExcelUtil<UserFactorItem>(UserFactorItem.class);
        util.exportExcel(response, list, "自定义因子数据");
    }

    /**
     * 获取自定义因子详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{factorItemId}")
    public AjaxResult getInfo(@PathVariable("factorItemId") String factorItemId)
    {
        return AjaxResult.success(userFactorItemService.selectUserFactorItemByFactorItemId(factorItemId));
    }

    /**
     * 新增自定义因子
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "自定义因子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFactorItemOp userFactorItemOp)
    {
        return AjaxResult.success(userFactorItemService.insertUserFactorItem(userFactorItemOp));
    }

    /**
     * 修改自定义因子
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "自定义因子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFactorItemOp userFactorItemOp)
    {
        return AjaxResult.success(userFactorItemService.updateUserFactorItem(userFactorItemOp));
    }

    /**
     * 删除自定义因子
     */
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "自定义因子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factorItemIds}")
    public AjaxResult remove(@PathVariable String[] factorItemIds)
    {
        return toAjax(userFactorItemService.deleteUserFactorItemByFactorItemIds(factorItemIds));
    }


}
